/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client.ui.workform;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.table.DefaultTableModel;

import proprietes.ConnectProprietes;
import proprietes.Protocol;

import client.core.io.Listner;
import client.core.io.conection.*;
import client.ui.ConnectionConfiguraiotn;

public class MainFormWork extends javax.swing.JFrame {

	private DefaultTableModel model;

	public MainFormWork() {
		Listner.getInstance();
		initComponents();
		initTableModel();
	}

	private void initTableModel() {

		model.addColumn("User nick");
		model.addColumn("Status");

		Conection c = new ClientToServer();
		c.createConection(ConnectProprietes.SERVER.getValue());
		c.sendRow(Protocol.GET_LIST_USERS.getValue());
		c.sendRow(Protocol.USER_NAME.getValue());
		String users = c.getRow();
		String s[] = users.split(";", -1);
		for (int i = 0; i < s.length - 1; i++) {
			String[] temp = { s[i], "false" };
			model.addRow(temp);
		}
		jTable1.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 2) {
					int row = jTable1.getSelectedRow();
					int col = jTable1.getSelectedColumn();
					
//					Conection c = new ClientToServer();
//					c.createConection(ConnectProprietes.SERVER.getValue());
//					c.sendRow(Protocol.GET_IP.getValue());
//					c.sendRow(jTable1.getValueAt(row, col).toString());
//					c.getRow();
					Conection c = new ClientToClient();
					c.createConection(ConnectProprietes.SERVER.getValue());
//					((ClientToClient)c).setDialogForm();
					new Thread(c).start();
				}
			}
		});
	}

	private void initComponents() {
		model = new MyDefaultTableModel();
		jScrollPane1 = new javax.swing.JScrollPane();
		jTable1 = new javax.swing.JTable(model);
		jMenuBar1 = new javax.swing.JMenuBar();
		jMenu1 = new javax.swing.JMenu();
		jMenu2 = new javax.swing.JMenu();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		jScrollPane1.setViewportView(jTable1);
		jMenu1.setText("File");
		jMenuBar1.add(jMenu1);

		jMenu2.setText("Edit");
		jMenuBar1.add(jMenu2);

		setJMenuBar(jMenuBar1);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 312,
				Short.MAX_VALUE));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 417,
				Short.MAX_VALUE));

		pack();
	}

	private javax.swing.JMenu jMenu1;
	private javax.swing.JMenu jMenu2;
	private javax.swing.JMenuBar jMenuBar1;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTable jTable1;
}
